// pages/QA/QA.js
var Data = require("../../Data/Data.js")
let app = getApp()
Page({

	data: {
    gradetext: '成绩：',
    grade: 0,//成绩
    questionnum: 8,//总数
    questions: Data.questions,//题库
    index: 0,//下标
    canAnswer: '',//是否可以答题
  },
//选项点击操作
Click: function(e){
	//获取点击元素的id
	var select = e.currentTarget.id;
	//获取点击问题的正确答案
	var A_answer = Data.questions[this.data.index].A_answer;
	var B_answer = Data.questions[this.data.index].B_answer;
	var C_answer = Data.questions[this.data.index].C_answer;
	var D_answer = Data.questions[this.data.index].D_answer;
	//答案正确
	if(select == A_answer){
		this.setData({
			grade: this.data.grade+3,//得分+3
		})
		app.globalData.grade = this.data.grade;
	}
	else if(select == B_answer){
		this.setData({
			grade: this.data.grade+2,//得分+2
		})
		app.globalData.grade = this.data.grade;
	}
	else if(select == C_answer){
		this.setData({
			grade: this.data.grade+1,//得分+1
		})
		app.globalData.grade = this.data.grade;
	}
	else if(select == D_answer){
		this.setData({
			grade: this.data.grade+0,//得分+0
		})
		app.globalData.grade = this.data.grade;
	}
	//不是最后一道题，跳转下一题
	if (this.data.index < this.data.questionnum - 1){
		this.NextQuestion();
	}
	//最后一道题
	else if (this.data.index == this.data.questionnum - 1){
		this.setData({
			canAnswer:'true'//禁止答题
		})
		this.GoEnd();
	}
},
//跳转下一道题
NextQuestion: function(){
	//不是最后一道题
	if (this.data.index < this.data.questionnum - 1){
		this.setData({
			index: this.data.index + 1,
		})
	}
	//最后一道题
	if (this.data.index == this.data.questionnum - 1) {
		this.setData({
			index: this.data.index,
		})
	}
},
//跳转结束页面
GoEnd:function(){
	wx.navigateTo({
		url: '/pages/End/End',
	})
},

})